package cn.edu.qvtu.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

/**
 * @FileName TimeAspect
 * @Description
 * @Author YooJia Chen
 * @date 2023-07-17
 */

@Slf4j
@Component
@Aspect
public class TimeAspect {
    //@Around("execution(* cn.edu.qvtu.service.*.*(..))") // 切入点表达式
    public Object recordTime(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        // 1.记录开始时间
        long begin = System.currentTimeMillis();
        // 2.调用原始方法运行
        Object objetc = proceedingJoinPoint.proceed(); // 调用原始方法运行
        // 3.记录结束时间，计算方法执行耗时
        long end = System.currentTimeMillis();
        log.info(proceedingJoinPoint.getSignature()+"执行耗时：{}ms", end - begin);
        return objetc;
    }
}
